package com.automation.ljf.exception.handler;

import com.automation.ljf.exception.BizException;
import com.automation.ljf.exception.type.ExceptionEnums;
import com.automation.ljf.util.ResultMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 类作用描述
 *
 * @author lijiefeng
 * @since 2021/9/2
 */
@RestControllerAdvice
@Slf4j
public class BizExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ResultMessage errorHandler(Exception e){
        log.error(e.toString());
        return ResultMessage.error(e.toString());
    }

    @ResponseBody
    @ExceptionHandler(BizException.class)
    public ResultMessage bizErrorHandler(ExceptionEnums exceptionEnums){
        log.error(exceptionEnums.getMsg());
        return ResultMessage.error(exceptionEnums.getCode(), exceptionEnums.getMsg());
    }

}
